package linguistic;

import java.util.List;
import java.util.Map;

import sets.FuzzySetType1;
import sets.IFuzzySet;
import sets.IntervalFuzzySet1;
import utils.Interval;

public class Summarizer {
	private String name;
	private IFuzzySet set;
	private String column;
	
	public void setName(String name) {
		this.name = name;
	}
	
	public String getName() {
		return name;
	}
	
	public void setColumn(String column) {
		this.column = column;
	}
	
	public String getColumn() {
		return column;
	}
	
	public void setFuzzySet(IFuzzySet set) {
		this.set = set;
	}
	
	public IFuzzySet getFuzzySet() {
		return this.set;
	}
	
	public void putTuples(List<Map<String, Double>> tuples) {
		if (tuples.size() > 0) {
			if (!tuples.get(0).containsKey(column)) {
				System.out.println("Critical Error! Column definition in Summarizer does not exist in database!");
				return;
			}
		}
		set.clearElements();
		for (int i = 0; i < tuples.size(); ++i) {
			double value = tuples.get(i).get(column);
			set.addElement(value);
		}
	}
	
	public double membershipValue(Map<String, Double> tuple) {
		double value = tuple.get(column);
		return set.getMembershipFunction().y(value);
	}
	
	public Interval intervalMembershipValue(Map<String, Double> tuple) {
		Interval interval = new Interval();
		double value = tuple.get(column);
		interval.setX(set.getLowerMembershipFunction().y(value));
		interval.setY(set.getUpperMembershipFunction().y(value));
		return interval;
	}
}
